package com.iespring.controller.admin.order;

import com.google.gson.Gson;
import com.iespring.bean.admin.order.RefundBO;
import com.iespring.bean.admin.order.bo.OrderListBo;
import com.iespring.bean.admin.order.bo.ShipBO;
import com.iespring.bean.admin.order.vo.DetailOrderVO;
import com.iespring.bean.admin.order.vo.OrderChannerVo;
import com.iespring.bean.admin.order.vo.OrderResultVo;
import com.iespring.bean.common.BaseParam;
import com.iespring.bean.common.BaseRespVo;
import com.iespring.exception.Param621Exception;
import com.iespring.service.order.OrderService;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 浩澄
 * @Date: 2022/12/28-20:35
 * @Mission: #订单模块
 */
@RestController
@RequestMapping("admin/order")
public class OrderController {
    @Autowired
    OrderService orderService;

    @RequestMapping("list")
    public BaseRespVo list(@Valid OrderListBo orderListBo, ArrayList<String> timeArray){

        OrderResultVo orderResultVo = orderService.list(orderListBo);
        return BaseRespVo.ok(orderResultVo);
    }

    @RequestMapping("channel")
    public BaseRespVo channel(){
        ArrayList<OrderChannerVo> orderChannerVos = new ArrayList<>();
        Gson gson = new Gson();
        List resp = gson.fromJson(s, orderChannerVos.getClass());
        return BaseRespVo.ok(resp);
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id){
        DetailOrderVO detailOrderVO = orderService.detail(id);
        return BaseRespVo.ok(detailOrderVO);
    }

//    @RequestMapping("refund")
//    public BaseRespVo refund() throws Param621Exception {
//        throw new Param621Exception("订单退款失败");
//    }

//    @RequestMapping("refund")
//    public BaseRespVo refund(@RequestBody RefundBO refundBO, HttpServletRequest request){
//        orderService.refund(refundBO,request);
//        return BaseRespVo.ok();
//    }
    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody RefundBO refundBO){
        orderService.refund(refundBO);
        return BaseRespVo.ok();
    }


//    @RequestMapping("delete")
//    public BaseRespVo delete(@RequestBody Map map, HttpServletRequest request){
//        Integer orderId = (Integer)map.get("orderId");
//        int code = orderService.delete(orderId, request);
//        if (code == 200){
//            return BaseRespVo.ok();
//        }else {
//        return BaseRespVo.error("订单不能删除",402);
//        }
//    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map map){
        Integer orderId = (Integer)map.get("orderId");
        int code = orderService.delete(orderId);
        if (code == 200){
            return BaseRespVo.ok();
        }else {
        return BaseRespVo.error("订单不能删除",402);
        }
    }

//    @RequestMapping("ship")
//    public BaseRespVo ship(@RequestBody ShipBO shipBO, HttpServletRequest request){
//        orderService.ship(shipBO,request);
//        return BaseRespVo.ok();
//    }

    @RequestMapping("ship")
    public BaseRespVo ship(@RequestBody ShipBO shipBO){
        orderService.ship(shipBO);
        return BaseRespVo.ok();
    }

String s = "[{\"code\":\"ZTO\",\"name\":\"中通快递\"},{\"code\":\"YTO\",\"name\":\"圆通速递\"},{\"code\":\"YD\",\"name\":\"韵达速递\"},{\"code\":\"YZPY\",\"name\":\"邮政快递包裹\"},{\"code\":\"EMS\",\"name\":\"EMS\"},{\"code\":\"DBL\",\"name\":\"德邦快递\"},{\"code\":\"FAST\",\"name\":\"快捷快递\"},{\"code\":\"ZJS\",\"name\":\"宅急送\"},{\"code\":\"TNT\",\"name\":\"TNT快递\"},{\"code\":\"UPS\",\"name\":\"UPS\"},{\"code\":\"DHL\",\"name\":\"DHL\"},{\"code\":\"FEDEX\",\"name\":\"FEDEX联邦(国内件)\"},{\"code\":\"FEDEX_GJ\",\"name\":\"FEDEX联邦(国际件)\"}]";





}
